package com.nts.bupna.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class If extends ConditionBase implements Activity, Iterable<If.ElseIf>
                                                    /*, Container<If.ElseIf>, Container<If.Else> */{

    private final List<ElseIf> elseIfs = new ArrayList<If.ElseIf>();

    private Else elseSub;

    @Override
    public ActivityType getActivityType() {
        return ActivityType.IF;
    }

    public void add(final ElseIf elseIf) {
        elseIfs.add(elseIf);
    }

    public void add(final Else elseSubParam) {
        this.elseSub = elseSubParam;
    }

    public Else getElse() {
        return elseSub;
    }

    @Override
    public Iterator<ElseIf> iterator() {
        return elseIfs.iterator();
    }

    public static class ElseIf extends ConditionBase {

        @Override
        public String toString() {
            return "ElseIf [condition=" + condition + ", activity=" + activity + "]";
        }
    }

    public static class Else implements Container<Activity> {

        private Activity activity;

        @Override
        public void add(final Activity activityParam) {
            activity = activityParam;
        }

        public Activity getActivity() {
            return activity;
        }

        @Override
        public String toString() {
            return "Else [activity=" + activity + "]";
        }
    }

    @Override
    public String toString() {
        return "If [condition=" + condition + ", activity=" + activity + ", elseIfs=" + elseIfs + ", elseSub="
                + elseSub + "]";
    }
}
